package handler

import (
	"context"
	"fmt"
	"zg5/videos/common/global"
	"zg5/videos/common/models"
	"zg5/videos/common/proto/users"
)

type Server struct {
	users.UnimplementedUserSrvServer
}

func (s *Server) UserInfo(_ context.Context, req *users.UserInfoRequest) (*users.UserInfoResponse, error) {

	var user models.Users
	global.DB.Debug().Where("id = ?", req.UserId).Find(&user)
	if user.ID == 0 {
		return nil, fmt.Errorf("用户信息异常")
	}

	return &users.UserInfoResponse{
		UserId:  uint64(user.ID),
		Image:   user.Image,
		Account: user.Account,
		Name:    user.Name,
		Text:    user.Text,
		Address: user.Address,
	}, nil
}
